// https://leetcode.cn/problems/missing-ranges/
// Created by ade on 2022/11/8.
// 输入: nums = [0, 1, 3, 50, 75], lower = 0 和 upper = 99,
//输出: ["2", "4->49", "51->74", "76->99"]
#include <vector>
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

class Solution {
public:
    vector <string> findMissingRanges(vector<int> &nums, int lower, int upper) {
        vector <string> res = {};
        for (int i = 0; i < nums.size(); i++) {
            if (lower > nums[i] - 1) {
                lower = nums[i] + 1;
                continue;
            }
            if (lower == nums[i] - 1) {
                res.push_back(to_string(lower));
                lower = nums[i] + 1;
                continue;
            }
            res.push_back(to_string(lower) + "->" + to_string(nums[i] - 1));
            lower = nums[i] + 1;
        }
        if (lower == upper - 1) {
            res.push_back(to_string(lower));
        } else if (lower < upper - 1) {
            res.push_back(to_string(lower) + "->" + to_string(upper));
        }

        return res;
    }
};

int main() {
    unordered_set<int> m = {2};
    cout << "find:" << *m.begin() << endl;
    return 0;
    Solution so;
    vector<int> nums = {0, 1, 3, 50, 75};
    auto res = so.findMissingRanges(nums, 0, 99);
    for (auto &i:res) {
        cout << i << ",";
    }
    cout << endl;
    return 0;
}